package com.clstu.tankgame3;

import java.awt.*;

public class Shot implements Runnable{
    private int x;
    private int y;
    private int speed = 8;
    private boolean isAlive = true;
    private Color color = null;
    private int der = -1;

    public Color getColor() {
        return color;
    }

    public Shot(int x, int y, boolean isAlive, int der, Color color) {
        this.x = x;
        this.y = y;
        this.isAlive = isAlive;
        this.der = der;
        this.color= color;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public boolean isAlive() {
        return isAlive;
    }

    public void setAlive(boolean alive) {
        isAlive = alive;
    }

    @Override
    public void run() {
        while (true){//子弹移动
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            switch (der){
                case 0://上
                    y-=speed;
                    break;
                case 1://左
                    x-=speed;
                    break;
                case 2://下
                    y+=speed;
                    break;
                case 3://右
                    x+=speed;
                    break;
                default:
                    System.out.println("设置的方向有误~~");
                    break;
            }
            if(!(x<=1000&&x>=0&&y>=0&&y<=750) || !(isAlive)){
                isAlive = false;
                System.out.println("子弹线程结束~~");
                break;
            }
        }
    }
}
